/**
 * Created by Administrator on 2017/2/15 0015.
 */
function selector(element) {
    return document.querySelectorAll(element)
};

function each(obj, callback) {
    if (isArrayLike(obj)) {
        for (var i = 0; i < obj.length; i++) {
            if (callback.call(obj[i], i, obj[i]) === false) break;
        }
    } else {
        for (var k in obj) {
            if (callback.call(obj[k], k, obj[k]) === false) break;
        }
    }
    return obj;
}

function map(obj, callback) {
    var arr = [], tmp;
    if (isArrayLike(obj)) {
        for (var i = 0; i < obj.length; i++) {
            tmp = callback(i, obj[i]);
            if (tmp != null) {
                arr.push(tmp);
            }
        }
    } else {
        for (var k in obj) {
            tmp = callback(k, obj[k]);
            if (tmp != null) {
                arr.push(tmp);
            }
        }
    }
    return arr;
}
//
//function isArrayLike(obj) {
//    if (Object.prototype.toString.call(obj).slice(8, -1) == "Array") {
//        return true;
//    }
//    var length = length in obj && obj.length;
//    return typeof length == "number" && length >= 0;
//}
//function $$(element) {
//    [].push.apply(this, $$.selector(element));
//}
//$$.prototype = {
//    select: function (element) {
//        return document.querySelectorAll(element)
//    },
//    each: function (callback) {
//        return $$.each(this, callback)
//    },
//    map: function (callback) {
//        return $$.map(this, callback)
//    }
//}
//$$.selector = function (element) {
//    return document.querySelectorAll(element)
//};
//$$.isArrayLike = function (obj) {
//    if (Object.prototype.toString.call(obj).slice(8, -1) == "Array") {
//        return true;
//    }
//    var length = 'length' in obj && obj.length;
//    return typeof length == "number" && length >= 0;
//
//}
//$$.each = function (obj, callback) {
//    if ($$.isArrayLike(obj)) {
//        for (var i = 0; i < obj.length; i++) {
//            if (callback.call(obj[i], i, obj[i]) === false) break;
//        }
//    } else {
//        for (var k in obj) {
//            if (callback.call(obj[k], k, obj[k]) === false) break;
//        }
//    }
//    return obj;
//};
//$$.map = function (obj, callback) {
//    var arr = [], tmp;
//    if ($$.isArrayLike(obj)) {
//        for (var i = 0; i < obj.length; i++) {
//            tmp = callback(obj[i], i);
//            if (tmp != null) {
//                arr.push(tmp);
//            }
//        }
//    } else {
//        for (var k in obj) {
//            tmp = callback(obj[k], k);
//            if (tmp != null) {
//                arr.push(tmp);
//            }
//        }
//    }
//    return arr;
//}
function $$(selector) {
    return new $$.prototype.init(selector);
}
$$.fn = $$.prototype = {
    constructor: $$,
    init: function (ele) {
        [].push.apply(this, $$.selector(ele));
    }
}

$$.fn.init.prototype = $$.fn;
window.$$ = window.$ = $$;

$$.extend = $$.fn.extend = function (obj) {
    for (var k in obj) {
        this[k] = obj[k];
    }
    return this;
}
$$.extend({
    selector: function (element) {
        return document.querySelectorAll(element)
    },
    each: function (obj,callback) {
        if ($$.isArrayLike(obj)) {
            for (var i = 0; i < obj.length; i++) {
                if (callback.call(obj[i], i, obj[i]) === false) break;
            }
        } else {
            for (var k in obj) {
                if (callback.call(obj[k], k, obj[k]) === false) break;
            }
        }
        return obj;
    },
    map: function (obj,callback) {
        var arr = [], tmp;
        if ($$.isArrayLike(obj)) {
            for (var i = 0; i < obj.length; i++) {
                tmp = callback(i, obj[i]);
                if (tmp != null) {
                    arr.push(tmp);
                }
            }
        } else {
            for (var k in obj) {
                tmp = callback(k, obj[k]);
                if (tmp != null) {
                    arr.push(tmp);
                }
            }
        }
        return arr;
    },
    isArrayLike: function (obj) {
        if (Object.prototype.toString.call(obj).slice(8, -1) == "Array") {
            return true;
        }
        var length = 'length' in obj && obj.length;
        return typeof length == "number" && length >= 0;
    }
});
$$.fn.extend({
    each: function (callback) {
        return $$.each(this, callback)
    },
    map: function (callback) {
        return $$.map(this, callback)
    },
})


//function $(selector) {
//    return new $$(selector);
//}
//for (var k in $$) {
//    $[k] = $$[k];
//}
//$.extend= function (name,func) {
//    $$.prototype[name]=func
//}